package com.example.learn_android;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


import androidx.annotation.Nullable;


public class ClickListener extends Activity {
    TextView text;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_click_listener);
        Button btn = findViewById(R.id.clickListener);

        text = findViewById(R.id.clickResult);
        btn.setOnClickListener(new MyClickListener(text));
    }

    static class MyClickListener implements View.OnClickListener {
        private final TextView text;

        public MyClickListener(TextView text) {
            this.text = text;
        }

        @Override
        public void onClick(View v) {
            text.setText("点击后文字展示");
        }
    }
}